(function () {
  var dictionary = {
    "语言": { en: "Language", zh: "语言" },
    "订单号": { en: "Order Number", zh: "订单号" },
    "客户": { en: "Customer", zh: "客户" },
    "日期": { en: "Date", zh: "日期" },
    "目的国": { en: "Destination Country", zh: "目的国" },
    "金额": { en: "Amount", zh: "金额" },
    "库存情况": { en: "Stock Status", zh: "库存情况" },
    "有库存": { en: "In Stock", zh: "有库存" },
    "无库存": { en: "Out of Stock", zh: "无库存" },
    "商品名称": { en: "Item Name", zh: "商品名称" },
    "物料组": { en: "Item Group", zh: "物料组" },
    "数量": { en: "Quantity", zh: "数量" },
    "仓库": { en: "Warehouse", zh: "仓库" },
    "库存": { en: "Stock", zh: "库存" },
    "该订单暂无商品": { en: "No items for this order", zh: "该订单暂无商品" },
    "第 {0}/{1} 页": { en: "Page {0} / {1}", zh: "第 {0}/{1} 页" },
    "提示": { en: "Notice", zh: "提示" },
    "订单数据加载失败，请稍后重试。": { en: "Failed to load orders, please try again later.", zh: "订单数据加载失败，请稍后重试。" },
    "订单数据加载失败。": { en: "Failed to load orders.", zh: "订单数据加载失败。" },
    "上一页": { en: "Previous", zh: "上一页" },
    "下一页": { en: "Next", zh: "下一页" },
    "查询": { en: "Search", zh: "查询" },
    "重置": { en: "Reset", zh: "重置" },
    "正在加载...": { en: "Loading...", zh: "正在加载..." },
    "暂无符合条件的订单": { en: "No matching orders", zh: "暂无符合条件的订单" },
    "Close": { en: "Close", zh: "关闭" },
    "My Profile": { en: "My Profile", zh: "我的资料" },
    "My Settings": { en: "My Settings", zh: "我的设置" },
  "Session Defaults": { en: "Active Company", zh: "当前公司" },
    "Log out": { en: "Log out", zh: "退出登录" },
    "Flowa • OMS": { en: "Flowa • OMS", zh: "Flowa • OMS" },
  "Flowa OMS订单管理系统": { en: "Flowa Order Management System", zh: "Flowa OMS 订单管理系统" },
    "一站式多平台订单管理 · 让数据发挥价值": { en: "Unified multi-platform order management", zh: "一站式多平台订单管理 · 让数据发挥价值" },
  "高效运营 · 智能驱动": { en: "Operate Smarter · Run Efficiently", zh: "高效运营 · 智能驱动" },
    "简体中文版": { en: "Simplified Chinese", zh: "简体中文版" },
    "English": { en: "English", zh: "English" },
    "首页": { en: "Home", zh: "首页" },
    "入库": { en: "Inbound", zh: "入库" },
    "出库": { en: "Outbound", zh: "出库" },
    "订单": { en: "Orders", zh: "订单" },
    "物流": { en: "Logistics", zh: "物流" },
    "仓库管理": { en: "Warehouse", zh: "仓库管理" },
    "供应链": { en: "Supply Chain", zh: "供应链" },
    "中转": { en: "Transit", zh: "中转" },
    "报表": { en: "Reports", zh: "报表" },
    "系统设置": { en: "System Settings", zh: "系统设置" },
    "充值对账": { en: "Billing & Recharges", zh: "充值对账" },
    "客服服务": { en: "Support", zh: "客服服务" },
  "入仓预报单": { en: "Inbound ASN", zh: "入仓预报单" },
  "装箱单": { en: "Packing List", zh: "装箱单" },
    "入库单": { en: "Stock Entry", zh: "入库单" },
    "Shopify订单": { en: "Shopify Orders", zh: "Shopify订单" },
    "订单操作日志": { en: "Order Operation Log", zh: "订单操作日志" },
    "出库单": { en: "Delivery Note", zh: "出库单" },
    "物料组管理": { en: "Item Group", zh: "物料组管理" },
    "Item 管理": { en: "Item", zh: "Item 管理" },
    "仓库地址管理": { en: "Address", zh: "仓库地址管理" },
    "仓库库存": { en: "Stock Balance", zh: "仓库库存" },
    "物流订单跟踪": { en: "Logistics Tracking", zh: "物流订单跟踪" },
    "异常物流单跟踪": { en: "Exception Tracking", zh: "异常物流单跟踪" },
    "物流标准 SOP": { en: "Logistics SOP", zh: "物流标准 SOP" },
    "物流产品签约": { en: "Logistics Product Sign", zh: "物流产品签约" },
    "充值管理": { en: "Recharge", zh: "充值管理" },
    "账期管理": { en: "Billing Cycle", zh: "账期管理" },
    "账单管理": { en: "Bills", zh: "账单管理" },
    "发票管理": { en: "Invoices", zh: "发票管理" },
    "汇总账单": { en: "Summary Bills", zh: "汇总账单" },
    "入库账单": { en: "Inbound Bills", zh: "入库账单" },
    "出库账单": { en: "Outbound Bills", zh: "出库账单" },
      "库存账单": { en: "Inventory Bills", zh: "库存账单" },
      "问题单管理": { en: "Issues", zh: "问题单管理" },
      "任务跟踪": { en: "Task Tracking", zh: "任务跟踪" },
    "员工账号管理": { en: "Staff Users", zh: "员工账号管理" },
    "店铺配置": { en: "Shop Settings", zh: "店铺配置" },
    "物流分拣配置": { en: "Picker Rules", zh: "物流分拣配置" },
    "企业编号": { en: "Enterprise ID", zh: "企业编号" },
    "企业编号：": { en: "Enterprise ID:", zh: "企业编号：" },
    "更多": { en: "More", zh: "更多" },
    "更多 >": { en: "More >", zh: "更多 >" },
    "剩余单量": { en: "Remaining Quota", zh: "剩余单量" },
    "查看单量日志": { en: "View Quota Log", zh: "查看单量日志" },
    "查看账户余额": { en: "View Balance", zh: "查看账户余额" },
  "当天预估物流费": { en: "Today's Estimated Logistics Fee", zh: "当天预估物流费" },
    "待办事项": { en: "To-Do", zh: "待办事项" },
    "品": { en: "SKU", zh: "品" },
    "商品": { en: "Items", zh: "商品" },
    "SKU总数": { en: "Total SKU", zh: "SKU总数" },
    "仓": { en: "Warehouse", zh: "仓" },
    "有库存商品数": { en: "Items In Stock", zh: "有库存商品数" },
    "存": { en: "Stock", zh: "存" },
    "库存总数": { en: "Total Inventory", zh: "库存总数" },
    "单": { en: "Orders", zh: "单" },
    "发货中": { en: "Shipping", zh: "发货中" },
    "今日新增": { en: "New Today", zh: "今日新增" },
    "今日发货量": { en: "Shipments Today", zh: "今日发货量" },
    "待审核": { en: "Pending Review", zh: "待审核" },
    "待出货": { en: "Pending Shipment", zh: "待出货" },
    "待发货": { en: "Pending Shipment", zh: "待发货" },
    "待发货": { en: "Pending Shipment", zh: "待发货" },
    "待收货": { en: "Pending Receipt", zh: "待收货" },
    "待开票": { en: "To Bill", zh: "待算费" },
    "待算费": { en: "To Bill", zh: "待算费" },
    "已完成": { en: "Completed", zh: "已完成" },
    "已发货": { en: "Shipped", zh: "已发货" },
    "已挂起": { en: "On Hold", zh: "已挂起" },
    "已关闭": { en: "Closed", zh: "已关闭" },
    "已取消": { en: "Cancelled", zh: "已取消" },
    "1日内 未发货": { en: "Not shipped within 1 day", zh: "1日内 未发货" },
    "2日内 未发货": { en: "Not shipped within 2 days", zh: "2日内 未发货" },
    "3日内 未发货": { en: "Not shipped within 3 days", zh: "3日内 未发货" },
    "3日外 未发货": { en: "Not shipped beyond 3 days", zh: "3日外 未发货" },
    "问题": { en: "Issue", zh: "问题" },
    "问题跟踪": { en: "Issue Tracking", zh: "问题跟踪" },
    "暂无需要跟踪的问题": { en: "No issues to track", zh: "暂无需要跟踪的问题" },
    "加载中...": { en: "Loading...", zh: "加载中..." },
    "异常订单": { en: "Exception Orders", zh: "异常订单" },
    "运送中订单": { en: "In Transit", zh: "运送中订单" },
    "已送达订单": { en: "Delivered", zh: "已送达订单" },
    "异常": { en: "Exceptions", zh: "异常" },
    "拦截": { en: "Intercepted", zh: "拦截" },
    "重要公告": { en: "Announcements", zh: "重要公告" },
    "暂无公告": { en: "No announcements", zh: "暂无公告" }
  };

  function detectLanguage() {
    if (window.frappe && window.frappe.boot) {
      return (window.frappe.boot.lang || window.frappe.boot.user_language || 'en').toLowerCase();
    }
    if (typeof window.getPreferredLanguage === 'function') {
      return window.getPreferredLanguage();
    }
    return (navigator.language || 'en').toLowerCase();
  }

  function translate(text) {
    if (!text) {
      return text;
    }
    var lang = detectLanguage();
    var entry = dictionary[text];
    if (!entry) {
      return text;
    }
    if (typeof entry === 'string') {
      return entry;
    }
    if (lang && entry[lang]) {
      return entry[lang];
    }
    if (lang && lang.startsWith('zh')) {
      return entry.zh || entry.en || text;
    }
    return entry.en || text;
  }

  window.flowaTranslations = dictionary;
  window.flowaTranslate = translate;
  if (typeof window.__ !== 'function') {
    window.__ = translate;
  }
})();


